var app = angular.module('crawlerApp');

app.controller('setCtrl', ['$scope', function($scope) {
  // 用于存放当前规则
  $scope.current = {};
  // 用于存放整套规则
  $scope.set = {
    // _id: ruleId,
    name: '模板',
    children: []
  };
  // 从某个父元素中删除某规则
  $scope.remove = function(parent, index) {
    parent.children.splice(index, 1);
  };

  // 选择当前规则
  $scope.choose = function(rule) {
    $scope.current = rule;
    console.log('choose', rule);
  };


  // 添加规则
  $scope.add = function(parent, e) {
    e.stopPropagation();
    $scope.init();
    console.log(parent, 'parent');
    parent.children.push($scope.current);
  };

  $scope.init = function() {
    $scope.current = {
      name: '新字段',
      children: []
    };
  };

  // 保存
  $scope.save = function(set) {
    console.log(set, 'save set');
  };

}]);
